package nc.impl.dm.m4804.rule;

import java.util.HashSet;
import java.util.Set;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.itf.scmpub.reference.uap.bd.currency.CurrencyInfo;
import nc.vo.dm.m4804.entity.DelivBillAggVO;
import nc.vo.dm.m4804.entity.DelivBillBVO;
import nc.vo.dm.m4804.entity.DelivBillPackVO;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;











public class CurrencyInfoCheck implements IRule<DelivBillAggVO> {
  public void process(DelivBillAggVO[] vos) {
    for (DelivBillAggVO vo : vos)
      checkCurrencyInfo(vo); 
  }



  private void checkCurrencyInfo(DelivBillAggVO vo) {
    Set<String> set = new HashSet<>();
    DelivBillBVO[] bvos = vo.getDelivBillBVO();
    DelivBillPackVO[] pvos = vo.getDelivBillPackVO();
    if (bvos != null && bvos.length > 0)
      for (DelivBillBVO bvo : bvos) {
        if (bvo.getCsettlefinorgid() != null)
          set.add(bvo.getCsettlefinorgvid()); 


      }  
    if (pvos != null && pvos.length > 0)
      for (DelivBillPackVO pvo : pvos) {
        if (pvo.getCsettlefinorgvid() != null)
          set.add(pvo.getCsettlefinorgvid()); 


      }  
    String headOrg = vo.getParentVO().getPk_org_v();
    set.add(headOrg);
    if (set.size() > 1) {

      Set<String> currtypeSet = new HashSet<>();
      String currtype = null;
      for (String str : set) {
        currtype = CurrencyInfo.getLocalCurrtypeByOrgID(str);
        currtypeSet.add(currtype);
        if (currtypeSet.size() > 1) {

          String message = NCLangRes4VoTransl.getNCLangRes().getStrByID("4014001_0", "04014001-0342");


          ExceptionUtils.wrappBusinessException(message);
        } 
      } 
    } 
  }
}
